define(function (require, exports, module) {
	var Grid = require("grid");
	var Dialog = require("dialog");
	
    var instance = {
    	renderGrid: function (widget,memberType,IndivMember) {
        	var defaultItems = [];
        	defaultItems = ([{
				name:"personalInfo.idNumber",
				label:"身份证号",
			},{
				name:"personalInfo.name",
				label:"姓名"
			},{
				name:"personalInfo.sex",
				label:"性别",
				format:function(value,data){
					if(value == "Male" || value.key == "Male"){
						return "男";
					}else{
						return "女";
					}
				}
			},{
				name:"personalInfo.mobilePhone",
				label:"手机号"
			}]);
        	if(memberType || IndivMember){
        		defaultItems.push({						
					name:"travelContract.productRule.product.name",
    				label:"权证名称",
				},{
    				name:"travelContract.memberCertificates",
    				label:"权证号",
    				format : function(value, row) {
						var travelContract = row.travelContract;
						if(travelContract==null){
							return "";
						}else{
							var idNumber = !travelContract.member ? "" : travelContract.member.personalInfo.idNumber;
							var name = !travelContract.member ? "" : travelContract.member.personalInfo.name
							return idNumber
							+ "-"
							+ name
							+ "-"
							+ travelContract.memberCertificates;
						}
        			},
    			})
        	};
        	defaultItems.push({
						name:"contactName",
						label:"紧急联系人"
					},{
						name:"contactPhone",
						label:"紧急电话"
					});
        	if(memberType){
        		defaultItems.push({
					name:"charge",
					label:"缴费状态",
					format:function(value,data){
						if(value){
							return "已缴费";
						}else{
							return "未缴费";
						}
					}
				});
        		defaultItems.push({
					name:"refund",
					label:"退费状态",
					format:function(value,data){
						if(value){
							return "已退费";
						}else{
							return "未退费";
						}
					}
				})
        	};
        	defaultItems.push({
				name:"operate",
				label:"操作",
				format:"button",
				formatparams:[{
					id:"exit",
					text: "退团",
					show: function(index,data,rowEle){
						if(data.exitGroup){
							return "已退团";
						}else{
							return true;
						}
					},
					handler:function(index,data,rowEle){
						var name = data.personalInfo.name,
						idNumber = data.personalInfo.idNumber;
						Dialog.confirm({
							title:"提示",
							content:"确定"+name+":"+idNumber+" 退出该团吗",
							confirm:function(){
								if(data.pkSignUpRegister){
									data.exitGroup = true;
									widget.exitData.push(data);
									widget.adjustTypes.push("Turnover");
								}
								subGrid.remove(index);
							}
						});
					}
				}]
			})
        	var subGrid = new Grid({
                parentNode: "#J-subGrid", 
                model : {
                    id:"subGrid",
                    head : {
						items : [ {
							id : "applyAdd",
							type : "button",
							text : "增加人员",
							handler : function() {
								widget.handler.applyAddEvent(widget);
							}
						} ]
					},
                    columns : defaultItems
                }
            });
            widget.set("subGrid",subGrid);
        }
    };
    module.exports = instance;
});